package com.google.memoryofaplace.controller;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

import com.google.memoryofaplace.model.TBJQueryParams;

public class ValidateParams extends HttpServlet {
	private static final long serialVersionUID = 3436320324826065302L;

	public static TBJQueryParams getParams(HttpServletRequest req) {
		try {
			if (req.getParameter("sEcho") != null
					&& req.getParameter("sEcho") != "") {
				TBJQueryParams param = new TBJQueryParams();
				param.sEcho = req.getParameter("sEcho");
				param.sSearch = req.getParameter("sSearch");
				param.sColumns = req.getParameter("sColumns");
				param.iDisplayStart = Integer.parseInt(req
						.getParameter("iDisplayStart"));
				param.iDisplayLength = Integer.parseInt(req
						.getParameter("iDisplayLength"));
				param.iColumns = Integer.parseInt(req.getParameter("iColumns"));
				param.iSortingCols = Integer.parseInt(req
						.getParameter("iSortingCols"));
				param.iSortColumnIndex = Integer.parseInt(req
						.getParameter("iSortCol_0"));
				param.sSortDirection = req.getParameter("sSortDir_0");
				return param;
			} else
				return null;
		} catch (Exception e) {
			return null;
		}
	}
}
